package com.han.flyweight;

import java.util.HashMap;

/**
 * @ClassName BoxFactory
 * @Description 工厂类，将该类设计为单例
 * @Author duoduo Han
 * @Date 2024/6/13 10:58
 */
public class BoxFactory {
    private HashMap<String, AbstractBox> map;

    //在构造方法中进行初始化
    private BoxFactory() {
        map = new HashMap<String, AbstractBox>();
        map.put("L", new LBox());
        map.put("I", new IBox());
        map.put("T", new TBox());
    }

    private static class BoxFactoryHolder {
        private static final BoxFactory INSTANCE = new BoxFactory();
    }
    //提供一个方法获取该工厂的实例
    public static BoxFactory getInstance() {
        return BoxFactoryHolder.INSTANCE;
    }

    //根据名称获取图形对象
    public AbstractBox getShape(String name) {
        return map.get(name);
    }


}
